<?php

require "./banco/Banco.php";

class BancoMySQL extends Banco{
	private $user;
	private $pass;
	private $server;
	
	public function __construct($pass='', $server='localhost', $user='root', $db='') {
		$this->setUser($user);
		$this->setPass($pass);
		$this->setServer($server);
		$this->setDb($db);
	}
	
	public function abrirConexao(){
		$this->setId( mysql_connect($this->getServer(), $this->getUser(), $this->getPass()) );
		if ( $this->getId() ) {
			if (mysql_select_db($this->getDb())) {
				return true;
			}
		}
		
		$this->setLastErro( mysql_error() );
		return false;
	}

	public function executaConsulta($sql=''){

		$this->setResultSet( mysql_query($sql) );

		if ( parent::getResultSet() ) {
			return true;
		} else {
			$this->setLastErro( mysql_error() );
			return false;
		}
	}

	public function executaComando($sql=''){
		
		if ( mysql_query($sql) ) {
			return true;
		} else {
			$this->setLastErro( mysql_error() );
			return false;
		}
	}

	public function fecharConexao(){
		if ( mysql_close($this->getId()) ) {
			return true;
		} else {
			$this->setLastErro( mysql_error() );
			return false;
		}
	}

	public function setUser($valor) {
		$this->user = $valor;
	}

	public function getUser() {
		return $this->user;
	}

	public function setPass($valor) {
		$this->pass = $valor;
	}

	public function getPass() {
		return $this->pass;
	}

	public function setServer($valor) {
		$this->server = $valor;
	}

	public function getServer() {
		return $this->server;
	}

	public function getResultSet() {
		$result = parent::getResultSet();

		while ($linha = mysql_fetch_array($result)) {
			$novoResult[] = $linha;
		}
		
		return $novoResult;
	}

}

?>